<?php

namespace app\admin\controller\contents;

use app\common\controller\Backend;


class Pingjia extends Backend
{

    protected $relationSearch = false;
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('orders');
    }

    /**
     * 查看
     */
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $newWhere = ['ispinglun'=>1];
            $total = $this->model
                ->where($newWhere)
                ->where($where)
                ->order($sort, $order)
                ->count();
            $list = $this->model
                ->where($newWhere)
                ->where($where)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();
            $yg_list=Model("yuangong")->select();
            foreach($yg_list as $v){
                $yg_info[$v['id']]=$v;
            }
            foreach ($list as $k => $v) {
                $v['order_tp_desc'] = $this->model->tpList($v['order_tp']);
                $v['yg_nickname'] =$yg_info[$v['yg_id']]['nickname'] ?? '-';
                $v['yg_truename'] =$yg_info[$v['yg_id']]['truename'] ?? '-';
                $v['atime'] =date("Y-m-d H:i:s",$v['etime']);
                //$v['sex'] = $this->model->sexList($v['sex']);
                //$v->hidden(['password', 'salt']);
            }
            $result = array("total" => $total, "rows" => $list);
            return json($result);
        }
        return $this->view->fetch();
    }
    public function info($ids=0){
        if($ids<1){
            $this->error('评论不存在');
        }
        $oinfo=Model('orders')->where(array('id'=>$ids))->find();
        if(empty($oinfo)){
            $this->error('订单不存在');
        }
        if($oinfo['ispinglun'] != 1){
            $this->error('该订单还未评价');
        }
        $this->view->assign('yg_info',Model('yuangong')->where(array('id'=>$oinfo['yg_id']))->find());
        $this->view->assign('oinfo',$oinfo);
        $this->view->assign('kehu',Model('kehu')->where(array('id'=>$oinfo['kehu_id']))->find());
        $info=Model('orders_pingjia')->where(array('order_id'=>$oinfo['id']))->find();
        $taidu='很好';
        $zhiliang='很好';
        if($info['taidu']==2){
            $taidu='一般';
        }elseif($info['taidu']==3){
            $taidu='差';
        }
        if($info['zhiliang']==2){
            $zhiliang='一般';
        }elseif($info['zhiliang']==3){
            $zhiliang='差';
        }
        $info['taidu']=$taidu;
        $info['zhiliang']=$zhiliang;
        $this->view->assign('info',$info);
        return $this->view->fetch();
    }
}
